package cn.neusoft.exception;

import cn.neusoft.vo.ResultBean;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = {Exception.class})  //出现异常就进入该方法
    @ResponseBody
    public <T> ResultBean<T> exceptionHandler(Exception e){
        //这里先判断拦截到的异常是不是我们自己定义的异常类型
        if(e instanceof AppException){
            AppException appException = (AppException) e;
            return ResultBean.error(appException.getCode(),appException.getMsg());
        }
        return ResultBean.error();
    }

}

